import React, { Component, createRef } from 'react'

// 需求：点击按钮显示 input 框并聚焦
export default class App extends Component {
  state = {
    bBar: false,
  }
  inputRef = createRef()
  handleClick = () => {
    this.setState({ bBar: !this.state.bBar }, () => {
      this.inputRef.current.focus()
    })
    // this.inputRef.current => inputDOM
  }
  render() {
    return (
      <div>
        <h2>App</h2>
        {this.state.bBar ? <input type='text' ref={this.inputRef} /> : null}
        <button onClick={this.handleClick}>回复</button>
      </div>
    )
  }
  componentDidUpdate() {
    // this.inputRef.current.focus()
  }
}
